// pages/index/index.js
const { loadData, getLuck } = require('../../api/index');
import Message from 'tdesign-miniprogram/message/index';
Page({
	onBannerTap(e) {
		const index = e.detail.index;
		// 根据索引获取对应的banner数据
		const banner = this.data.banners[index];
		// 跳转到详情页，传递id参数
		wx.navigateTo({
			url: "/pages/goodsDetail/goodsDetail?id=${banner.id}"
		});
	},
	onIdentityCardTap(e){
		wx.navigateTo({
			url: "/pages/personalInfo/personalInfo"
		});
	},
	onIdentityqrCodeTap(e){
		wx.navigateTo({
			url: "/pages/qrCode/qrCode"
		});
	},
	onNavigationCardTap(e){
		const index = e.currentTarget.dataset.index;
		switch (index){
			case 0:
				wx.navigateTo({
					url: "/pages/personalHealth/personalHealth"
				});
				break;
			case 1:
				wx.navigateTo({
					url: "/pages/careForTa/careForTa"
				});
				break;
			case 2:
				wx.navigateTo({
					url: "/pages/sendHealth/sendHealth"
				});
				break;
			default:
				wx.navigateTo({
					url: "/pages/lifeGuan/lifeGuan"
				});
				break;
		}
	},
	onArticlePushTap(e){
		const id = e.currentTarget.dataset.id;
		wx.navigateTo({
			url: "/pages/articleDetail/articleDetail?id=${id}"
		});
	},
	clickLuck(e){
		getLuck().then(res=>{
			Message.info({
				offset: [90, 32],
				marquee: { speed: 100, loop: -1 },
				icon: false,
				content: res.content,
				duration: 5000,
			});
		})
	},
	/**
	 * 页面的初始数据
	 */
	data: {
		banners:[],
		identityCard:{},
		navigationCard:[],
		articlePush:[],
	},

	/**
	 * 生命周期函数--监听页面加载
	 */
	onLoad(options) {
		loadData().then(res => {
			this.setData({
				banners: res.banners
			})
			this.setData({
				identityCard: res.identityCard
			})
			this.setData({
				navigationCard:res.navigationCard
			})
			this.setData({
				articlePush:res.articlePush
			})
		})
	},

	/**
	 * 生命周期函数--监听页面初次渲染完成
	 */
	onReady() {

	},

	/**
	 * 生命周期函数--监听页面显示
	 */
	onShow() {

	},

	/**
	 * 生命周期函数--监听页面隐藏
	 */
	onHide() {

	},

	/**
	 * 生命周期函数--监听页面卸载
	 */
	onUnload() {

	},

	/**
	 * 页面相关事件处理函数--监听用户下拉动作
	 */
	onPullDownRefresh() {

	},

	/**
	 * 页面上拉触底事件的处理函数
	 */
	onReachBottom() {

	},

	/**
	 * 用户点击右上角分享
	 */
	onShareAppMessage() {

	}
})

const data11 = {
	"statusCode": 200,
	"message": "success",
	"data": {
		"banners":[
			{
				"id": "1",
				"value": "https://tdesign.gtimg.com/mobile/demos/swiper1.png"
			},
			{
				"id": "2",
				"value": "https://tdesign.gtimg.com/mobile/demos/swiper1.png"
			}
		],
		"identityCard":{
			"img": "https://tdesign.gtimg.com/mobile/demos/avatar1.png",
			"name": "张三",
			"description": "一段很长很长的内容文字",
			"icon": "https://tdesign.gtimg.com/mobile/demos/icon1.png",
			"iconText":"会员码"
		},
		"navigationCard":[
			{
				"icon": "https://tdesign.gtimg.com/mobile/demos/icon1.png",
				"iconText":"个人健康"},
			{
				"icon": "https://tdesign.gtimg.com/mobile/demos/icon1.png",
				"iconText":"关心TA"},
			{
				"icon": "https://tdesign.gtimg.com/mobile/demos/icon1.png",
				"iconText":"送健康"},
			{
				"icon": "https://tdesign.gtimg.com/mobile/demos/icon1.png",
				"iconText":"生活馆"
			}
		],
		"articlePush":[
			{
				"id":"1",
				"img": "https://tdesign.gtimg.com/mobile/demos/avatar1.png",
				"title": "标题",
				"content": "内容"
			},
			{
				"id":"2",
				"img": "https://tdesign.gtimg.com/mobile/demos/avatar1.png",
				"title": "标题",
				"content": "内容"
			},
			{
				"id":"3",
				"img": "https://tdesign.gtimg.com/mobile/demos/avatar1.png",
				"title": "标题",
				"content": "内容"
			}
		]
	}
}